package com.yuting.springbootcore;

import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.connector.Connector;
import org.apache.catalina.startup.Tomcat;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;

public class SpringApplication {


    public static void run(Class<?> clazz, Object[] args) throws LifecycleException, ClassNotFoundException, IllegalAccessException, InstantiationException {
        Tomcat tomcat = new Tomcat();

        tomcat.setPort(8080);

        Context context = tomcat.addContext("/", System.getProperty("java.io.tmpdir"));
        context.addLifecycleListener((LifecycleListener) Class.forName(tomcat.getHost().getConfigClass()).newInstance());
        tomcat.start();
        tomcat.getServer().await();
    }
}
